﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HelperSomthing;

namespace UpToSQL
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); 
        }


        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            //打开窗口
            openFileDialog1.ShowDialog();
            string filename = openFileDialog1.FileName;//文件的路径
            label2.Text = filename;

            int last = filename.LastIndexOf(".");
            string name = filename.Substring(last, filename.Length-1);

            switch (filename)
            {


                default:
                    break;
            }

            if (filename!="")
            {
                //excel获取数据
                List<string> ToSql = NPOIHelper.ExcelToSql(filename, true);

                bool success = false;

                ToSql.ForEach(b =>
                {
                    success = SqlServerHelper.ExecuteNonQuery(b) > 0 ? true : false;
                    
                    if (success == false)
                        FiledTiao.Text += b + "\n";
                    else
                        richTextBox1.Text += b + "\n";    
                });

                MessageBox.Show(success == true ? "已添加成功" : "添加失败");
            }
            

            
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
